Skip to content

feat: selfmonitor metrics support dynamic labels and gc#2496

Open
shunjiazhu wants to merge 8 commits into
alibaba:mainfrom
shunjiazhu:feat/self-monitor-dynamic-labels
Open

feat: selfmonitor metrics support dynamic labels and gc#2496
shunjiazhu wants to merge 8 commits into
alibaba:mainfrom
shunjiazhu:feat/self-monitor-dynamic-labels

Conversation

@shunjiazhu
Copy link
Copy Markdown
Contributor

@shunjiazhu shunjiazhu commented Dec 21, 2025

Change-Id: I74af3156bbc37e047cfc7f7b6c26a807973aceb5

  1. 自监控API,支持在打点时动态的传入TagValue,用于观测在插件初始化时无法确定label value的场景,比如http code等。
// ExportMetricRecords exports all metrics bound to this metric record.
// The results may be a list of map[string]string, each map[string]string is a set of measurements has the same labels.
// for example:
// []{
// {"counters":"{\"http_flusher_dropped_events\":\"3.0000\",\"http_flusher_flush_failure_count\":\"6.0000\",\"http_flusher_matched_events\":\"1.0000\",\"http_flusher_retry_count\":\"5.0000\",\"http_flusher_unmatched_events\":\"2.0000\"}","gauges":"{\"http_flusher_flush_latency_ns\":\"7.0000\"}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\"}"}
// {"counters":"{\"http_flusher_status_code_count\":\"8.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"status_code\":\"200\"}"}
// {"counters":"{\"http_flusher_status_code_count\":\"9.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"status_code\":\"400\"}"}
// {"counters":"{\"http_flusher_error_count\":\"10.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"level\":\"error\",\"reason\":\"timeout\"}"}
// {"counters":"{\"http_flusher_error_count\":\"11.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"level\":\"warn\",\"reason\":\"retry\"}"}
// {"counters":"{\"http_flusher_error_count\":\"12.0000\"}","gauges":"{}","labels":"{\"PluginId\":\"13\",\"PluginType\":\"flusher_http\",\"RemoteURL\":\"http://localhost:8081\",\"level\":\"error\",\"reason\":\"dropped\"}"}
// }
// Note:
// A metric may have three levels of labels
// 1. MetricsRecord Level Const Labels, like PluginType=flusher_http, PluginId=1
// 2. Metric Level Const Labels, for example, flusher_http may have a const label: RemoteURL=http://aliyun.com/write
// 3. Metric Level Dynamic Labels, like status_code=200, status_code=204
  1. 自监控支持序列过期,当一个指标的一个特定的Tags组合长期没有打点时,允许其gc掉,防止因为内存中常驻维度过高而产生的内存开销。
	cumulativeCounter := NewCumulativeCounterMetricVector("test", constLabels, getTagNames(allTags),
		WithExpiration(time.Hour),
		WithCardinalityLimit(1000),
	)

Change-Id: I74af3156bbc37e047cfc7f7b6c26a807973aceb5
…mic-labels

Change-Id: Ic6dc62cf5675332857d79385be33f522c9f8c97c
Change-Id: I68d30400a1c319ed3a79235c4931825c907b20b8
Change-Id: If2681139c5acec1ea11b317558cf92b63b3fa48e
Change-Id: Id1d9a4eafd958bee780a617db5874d587f0148cb
Change-Id: I7054bded1154c5d653129262e052215f0106f5a3
Change-Id: I61956711952f596559f9be940cfd746d60191403
…mic-labels

Change-Id: Ica0541be7679d97cbd81b1f598e5c2865e047841
@Takuka0311
Copy link
Copy Markdown
Collaborator

Takuka0311 commented Apr 27, 2026

百炼自动化审查:建议保持开启。

本 PR 为自监控模块引入动态标签与指标序列 GC 机制,并修改了核心 API ExportMetricRecords 的返回类型。当前 PR 落后于 main 分支存在合并冲突,且涉及向后兼容性变更,需维护者评估 API 签名调整对下游插件的影响及并发安全性。建议保持开启,等待作者 rebase 及维护者审查。.

最佳落地路径:

建议作者 rebase main 解决冲突。维护者需审查 ExportMetricRecords 返回值变更的兼容性、动态标签 GC 的并发安全与高基数控制策略。CI 通过且审查完成后可合入。.

已核对内容:

百炼审查备注:模型 qwen3.6-max-preview;对照提交 30ac854deafd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants